cmake_minimum_required(VERSION 3.20)
project(LeoBase VERSION 1.0.0 LANGUAGES CXX)

# 设置C++标准
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# FetchContent模块用于下载和管理外部依赖
set(FETCHCONTENT_QUIET OFF)
include(FetchContent)

# ------------------------------------------------------------------------------
# 依赖管理
# ------------------------------------------------------------------------------

# 1. spdlog (日志引擎)
# 使用内置 fmt 库以减少依赖冲突
set(SPDLOG_FMT_EXTERNAL OFF CACHE BOOL "" FORCE)
FetchContent_Declare(
    spdlog
    GIT_REPOSITORY https://github.com/gabime/spdlog.git
    GIT_TAG        v1.14.1
    GIT_PROGRESS   TRUE
)

# 2. nlohmann_json (JSON 处理)
FetchContent_Declare(
    json
    GIT_REPOSITORY https://github.com/nlohmann/json.git
    GIT_TAG        v3.11.3
    GIT_PROGRESS   TRUE
)

# 3. sentry-native (崩溃捕获)
# 强制设置 Crashpad 后端
set(SENTRY_BACKEND "crashpad" CACHE STRING "The sentry backend" FORCE)
FetchContent_Declare(
    sentry-native
    GIT_REPOSITORY https://github.com/getsentry/sentry-native.git
    GIT_TAG        master
    GIT_PROGRESS   TRUE
)

# 使依赖可用
FetchContent_MakeAvailable(spdlog json sentry-native)

# ------------------------------------------------------------------------------
# 构建目标
# ------------------------------------------------------------------------------

add_executable(helloworld src/main.cpp src/leomedlog/leomedlog.cpp)

# 包含目录
target_include_directories(helloworld PRIVATE 
    include
)

#MSVC的编译选择项
#/W0  # 关闭所有警告
#/W1  # 只显示严重警告
#/W2  # 显示较重要的警告（默认）
#/W3  # 显示开发建议级别的警告
#/W4  # 最高实用级别（包含大量代码质量警告）
#/Wall # 显示**所有**警告（包括微软库自身的警告，极度过量）
#GCC/Clang的编译选项
#-Wall      # 通用警告
#-Wextra    # 额外警告（如未使用参数）
#-Wpedantic # 严格遵循标准
#-Wconversion # 隐式类型转换
if(MSVC)
    target_compile_options(helloworld PRIVATE /W4)
else()
    target_compile_options(helloworld PRIVATE -Wall -Wextra)
endif()

# 链接库
target_link_libraries(helloworld 
    PRIVATE 
    spdlog::spdlog
    nlohmann_json::nlohmann_json
    sentry::sentry
)

# Copy crashpad_handler to the output directory
if(TARGET crashpad_handler)
    add_custom_command(TARGET helloworld POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_if_different
        $<TARGET_FILE:crashpad_handler>
        $<TARGET_FILE_DIR:helloworld>
        COMMENT "Copying crashpad_handler to output directory"
    )
endif()
